<template>
  <div>
    <!-- 顶部 -->
    <el-card>
      <!-- 绑定一个自定义事件:让子元素给父元素传递分类的id -->
      <Category @getCategoryId="getCategoryId" />
    </el-card>
    <!-- 底部 -->
    <el-card style="margin: 20px 0px"> 底部 </el-card>
  </div>
</template>

<script>
export default {
  name: "Attr",
  data() {
    return {
      //存储子组件传递过来的分类id
      category1Id: "",
      category2Id: "",
      category3Id: "",
    };
  },
  methods: {
    //平台属性父组件的方法
    getCategoryId({ id, flag }) {
      //需要父组件存储相应一级、二级、三级分类的id
      switch (flag) {
        case 1:
          this.category1Id = id;
          //清除二级、三级分类的id
          this.category2Id = '';
          this.category3Id = '';
          break;
        case 2:
          this.category2Id = id;
          this.category3Id = '';
          break;
        case 3:
          this.category3Id = id;
          break;
      }
    },
  },
};
</script>

<style scoped>
</style>
